//引入API文件直接进行请求
import * as api from '@/utils/api.js'
const state={
    address:[],
    info:{},
    payInfo:{}
};
const mutations={
    GETUSERADDRESS(state,address){
        state.address=address
    },
    GETORDEINFO(state,info){
        state.info=info
    },
    PAYINFO(state,payInfo){
        state.payInfo=payInfo
    }
};
const actions={
    async userAddressList({commit}){
        const res=await api.userAddressList()
        if (res.code===200) {
            commit('GETUSERADDRESS',res.data)
        }
    },
    async trade({commit}){
        const res=await api.trade()
        if (res.code===200) {
           commit('GETORDEINFO',res.data)
        } 
    },
    async submitOrder({commit},params){
        const res=await api.submitOrder(params.tradeNo,params.data)
        if (res.code===200) {
            console.log(commit)
            return res.data
        } else {
            return Promise.reject(new Error(res.message))   
        }
    },
    async createNative({commit},orderId){
        const res=await api.createNative(orderId)
        if (res.code===200) {
            commit('PAYINFO',res.data)
            return 'ok'
        }else{
            return Promise.reject(new Error(res.message))   
        }
    }
};
const getters={
}
export default{
    state,
    mutations,
    actions,
    getters
}